package com.linkzd.iot.controller;

import com.linkzd.common.core.controller.BaseController;
import com.linkzd.common.core.domain.AjaxResult;
import com.linkzd.iot.domain.DeviceInfo;
import com.linkzd.iot.domain.RoomInfo;
import com.linkzd.iot.domain.SensorsReportDataLog;
import com.linkzd.iot.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/index")
public class IndexController extends BaseController
{
    @Autowired
    private IIndexService indexService;
    @Autowired
    private ISensorsReportDataLogService sensorsReportDataLogService;

    @Autowired
    private IDeviceTypeService deviceTypeService;

    @Autowired
    private IDeviceInfoService deviceInfoService;

    @Autowired
    private IRoomInfoService roomInfoService;

    /** @Author Wangym
     * @Date 2024/5/29 下午 11:01
     * @Description 大屏设备总览查询
     * @Param
     * @Return 
     **/
    @GetMapping("/overview")
    public AjaxResult overview()
    {
        return success(indexService.selectDeviceOverview());
    }


/** @Author Wangym
 * @Date 2024/5/30 上午 10:05
 * @Description 执行器在离线
 * @Param
 * @Return
 **/
    @GetMapping("/onlineOrOffline")
    public AjaxResult onlineOrOffline()
    {
        return success(indexService.onlineOrOffline());
    }
    
    /** @Author Wangym
     * @Date 2024/5/30 上午 10:04
     * @Description 查询平台下发设备的开关在线离线动态
     * @Param
     * @Return 
     **/
    @GetMapping("/getDataLog")
    public AjaxResult getDataLog()
    {
        return success(indexService.getDataLog());
    }


    /** @Author Wangym
     * @Date 2024/5/30 上午 10:04
     * @Description 查询传感器主动上报数据表
     * @Param
     * @Return
     **/
    @GetMapping("/failureAlarm")
    public AjaxResult failureAlarm()
    {
        DeviceInfo deviceInfo = new DeviceInfo();
        deviceInfo.setDeviceState(0);
        return success(deviceInfoService.selectDeviceInfoList(deviceInfo));
    }



    /** @Author Wangym
     * @Date 2024/5/30 上午 10:04
     * @Description 查询传感器主动上报数据表
     * @Param
     * @Return
     **/
    @GetMapping("/floorRoomNumber")
    public AjaxResult floorRoomNumber()
    {
        return success(roomInfoService.selectRoomInfoNum());
    }


    /** @Author Wangym
     * @Date 2024/5/30 上午 10:04
     * @Description 查询传感器主动上报数据表
     * @Param
     * @Return
     **/
    @GetMapping("/equipmentOperations")
    public AjaxResult equipmentOperations()
    {
        return success(deviceInfoService.equipmentOperations());
    }


    /** @Author Wangym
     * @Date 2024/5/30 上午 10:04
     * @Description 查询根据房间号的温湿度均值
     * @Param
     * @Return
     **/
    @GetMapping("/meanTemperatureHumidity/{roomNum}")
    public AjaxResult meanTemperatureHumidity( @PathVariable  String roomNum)
    {

        return success(sensorsReportDataLogService.meanTemperatureHumidity(roomNum));
    }


    /*******************************以下是大棚代码******************************/

    /** @Author Wangym
     * @Date 2024/5/30 上午 10:04
     * @Description 查询根据房间号的温湿度均值
     * @Param
     * @Return
     **/
    @GetMapping("/getRoomNums")
    public AjaxResult getRoomNums()
    {
        return success(roomInfoService.selectRoomInfoList(new RoomInfo()));
    }



    /** @Author Wangym
     * @Date 2024/5/30 上午 10:04
     * @Description 查询根据房间号的温湿度均值
     * @Param
     * @Return
     **/
    @GetMapping("/getRoomEquipmentData/{roomNum}")
    public AjaxResult getRoomEquipmentData( @PathVariable  String roomNum)
    {
        RoomInfo roomInfo = new RoomInfo();
        roomInfo.setRoomNum(roomNum);
        return success(indexService.selectDeviceInfoList(roomInfo));
    }
}
